﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DomainModel;
using Utils;
using WebUI.Utils;
using System.ComponentModel.DataAnnotations;
using DataAnnotationsExtensions;

namespace WebUI.Models
{
    public class JobPayNonLoggedInViewModel : BaseViewModel
    {
        public JobPayNonLoggedInViewModel()
            : base()
        { }

        public JobPayNonLoggedInViewModel(string jobToken)
            : base(new { JobToken = jobToken })
        { }

        public string StripeToken { get; set; }

        [Required]
        [UserName]
        [NoHtml]
        [Display(Name = "User name")]
        [StringLength(20, ErrorMessage = "The User name field has maximum 20 characters")]
        public string UserName { get; set; }

        [Required]
        [Email]
        [Display(Name = "Email")]
        [StringLength(48, ErrorMessage = "The Email field has maximum 48 characters")]
        public string Email { get; set; }

        [Required]
        [StringLength(32, MinimumLength = 6, ErrorMessage = "The Password field has minimum 6 characters and maxinum 32 characters")]
        [DataType(DataType.Password)]
        [Display(Name = "Password")]
        public string Password { get; set; }


        public Job Job { get; set; }
        public Co Co { get; set; }

        public int JobPackageID { get; set; }
        public IEnumerable<SelectListItem> JobPackageList { get; set; }

        protected override void SetVars()
        {
            
        }

        protected override void SetVarsWhichDependOnDynamicParams(dynamic dynParams)
        {
            string jobToken = dynParams.JobToken;
            //JobToken in cooke contains JobGUID-JobID pair
            string jobGUID = ViewModelUtils.GetJobGUIDFromToken(jobToken);
            int jobID = ViewModelUtils.GetJobIDFromToken(jobToken);
            //companyID
            int coID = 0;//Identity.IsCoLoggedIn ? Identity.AccountID : 0;
            
            //for any case, just call this to get CoJob
            CoJob coJob = DataUtils.GetCoJobByJobTokenAndCoID(jobGUID, jobID, coID);
            Job = coJob.Job;
            Co = coJob.Co;
        }

        public override void SetPublicVarsAfterBindingDynamicParams()
        {
            JobPackageList = ViewModelUtils.GetSelectListItems(GlobalUtilities.GetInstance().JobPackageList, JobPackageID);
        }
    }

    public class JobPayLoggedInWithCreditsViewModel : BaseViewModel
    {
        public JobPayLoggedInWithCreditsViewModel()
            : base()
        { }

        public JobPayLoggedInWithCreditsViewModel(string jobToken)
            : base(new { JobToken = jobToken })
        { }

        public string JobToken { get; set; }
        public Job Job { get; set; }
        public Co Co { get; set; }

        protected override void SetVarsWhichDependOnDynamicParams(dynamic dynParams)
        {
            string jobToken = dynParams.JobToken;
            //JobToken in cooke contains JobGUID-JobID pair
            string jobGUID = ViewModelUtils.GetJobGUIDFromToken(jobToken);
            int jobID = ViewModelUtils.GetJobIDFromToken(jobToken);
            //companyID
            int coID = Identity.AccountID;

            //for any case, just call this to get CoJob
            CoJob coJob = DataUtils.GetCoJobByJobTokenAndCoID(jobGUID, jobID, coID);
            Job = coJob.Job;
            Co = coJob.Co;
        }
    }

    public class JobPayLoggedInWithoutCreditsViewModel : BaseViewModel
    {
        public JobPayLoggedInWithoutCreditsViewModel()
            : base()
        { }

        public JobPayLoggedInWithoutCreditsViewModel(string jobToken)
            : base(new { JobToken = jobToken })
        { }

        public string StripeToken { get; set; }

        public string JobToken { get; set; }
        public Job Job { get; set; }
        public Co Co { get; set; }

        public int JobPackageID { get; set; }
        public IEnumerable<SelectListItem> JobPackageList { get; set; }

        protected override void SetVarsWhichDependOnDynamicParams(dynamic dynParams)
        {
            string jobToken = dynParams.JobToken;
            //JobToken in cooke contains JobGUID-JobID pair
            string jobGUID = ViewModelUtils.GetJobGUIDFromToken(jobToken);
            int jobID = ViewModelUtils.GetJobIDFromToken(jobToken);
            //companyID
            int coID = Identity.AccountID;

            //for any case, just call this to get CoJob
            CoJob coJob = DataUtils.GetCoJobByJobTokenAndCoID(jobGUID, jobID, coID);
            Job = coJob.Job;
            Co = coJob.Co;
        }

        public override void SetPublicVarsAfterBindingDynamicParams()
        {
            JobPackageList = ViewModelUtils.GetSelectListItems(GlobalUtilities.GetInstance().JobPackageList, JobPackageID);
        }
    }

    public class BuyCreditsViewModel : BaseViewModel
    {
        public BuyCreditsViewModel()
            : base()
        { }
        
        public string StripeToken { get; set; }

        public int JobPackageID { get; set; }
        public IEnumerable<SelectListItem> JobPackageList { get; set; }

        protected override void SetVars()
        {
            JobPackageList = ViewModelUtils.GetSelectListItems(GlobalUtilities.GetInstance().JobPackageList, JobPackageID);
        }
    }
}